package com.fifth.business.controller;

import com.fifth.business.service.BusinessService;
import com.fifth.business.untils.OSSUtil;
import com.fifth.business.untils.Sample;
import com.fifth.common.pojo.dto.CommonResult;
import com.fifth.common.pojo.entity.BusinessInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * @作者：刘壬杉
 * @创建时间 2022/8/31 11:37
 **/
@RestController
@RequestMapping("business")
public class BusinessController {
    @Autowired
    private BusinessService businessService;



    /**
     * 获取商户信息
     * @return
     */
    /*@GetMapping("/storemanagement")
    public CommonResult storemanagement(Integer currentPage,Integer pageSize,BusinessInfo businessInfo){
    CommonResult commonResult =  businessService.selectAll(currentPage,pageSize,businessInfo);
      return new CommonResult(2000,"查寻成功",commonResult);

    }*/




    /**
     * 根据id删除
     */
    @GetMapping("/storedelete/{id}")
    public CommonResult Storedelete(@PathVariable String id){
     CommonResult storedelete= businessService.storedelete(id);
        return new CommonResult(2000,"删除成功",storedelete);
    }

    /**
     * 添加
     */
    @PostMapping("/storeinsert")
    public CommonResult StoreInsert(@RequestBody BusinessInfo businessInfo){

        CommonResult storeinsert= businessService.storeinsert(businessInfo);
        return new CommonResult(2000,"添加成功",storeinsert);
    }

    /**
     * 修改
     */
    @GetMapping("/storeupdate")
    public CommonResult StoreUpdate(@RequestBody BusinessInfo businessInfo){
        CommonResult storeupdate= businessService.storeupdate(businessInfo);
        return new CommonResult(2000,"修改成功",storeupdate);
    }




    /**
     * 修改商户信息营业状态
     */
    @GetMapping("/updatestore/{businessInfo}")
    public CommonResult updatestore(@PathVariable BusinessInfo businessInfo){
        System.out.println(businessInfo);
        CommonResult commonResult = businessService.updateById(businessInfo);
        return new CommonResult(2000,"修改成功",commonResult);

    }


    /**
     * 查询店铺信息
     */
    @GetMapping("/queryshop")
    public CommonResult queryshop() {
        CommonResult queryshop = businessService.queryshop();
        return new CommonResult(2000,"查询成功",queryshop);
    }




    /**
     * 图片上传
     * @param file
     * @return
     */
    @PostMapping("/upload")
    public CommonResult uplocad(MultipartFile file){
        try{
            String upload = OSSUtil.upload(file);
            return new CommonResult(2000,"上传成功",upload);
        }catch (Exception e){
            e.printStackTrace();
        }
        return new CommonResult(5000,"上传失败",null);
    }

    /**
     * 查询所有商铺
     */
    @GetMapping("selectshop")
    public CommonResult selectshop(){
        return businessService.selectshop();
    }


    /**
     * 用户申请商家审核查询所有店铺
     */
    @PostMapping("loadingshop")
    public CommonResult allshop(@RequestBody BusinessInfo businessInfo,@RequestParam(defaultValue = "1") Integer currentPage, @RequestParam(defaultValue = "5") Integer pageSize){
        return businessService.loadlingshop(businessInfo, currentPage, pageSize);}

    /**
     * 对用户提交审核修改状态
     */
    @PostMapping("loadingstatus")
    public CommonResult loadingstatus(@RequestBody BusinessInfo businessInfo){

        return businessService.loadingstatus(businessInfo);}

    /**
     * 查询登录商家信息
     */
    @GetMapping("showshop")
    public CommonResult showshop(){
        return businessService.showshop();
    }
    /**
     * 修改登录商家个人信息
     */
    @PostMapping("changeshop")
    public CommonResult changeshop(@RequestBody BusinessInfo businessInfo){
        return businessService.changeshop(businessInfo);
    }
    /**
     * 商家修改密码
     */
    @PostMapping("changepass/{telephone}/{password}")
    public CommonResult changepass(@PathVariable String telephone, @PathVariable String password){
     return businessService.changepass(telephone, password);
    }
    /**
     * 获取商家验证码
     */
    @GetMapping("noteByPhone/{telephone}")
    public CommonResult noteByPhone(@PathVariable String telephone)throws Exception{
        String note = Sample.sendCode(telephone);
        return new CommonResult(2000,"发送验证码成功",note);
    }

    /**
     * 根据token手机号查询当前用户登录身份
     */
    @GetMapping("tokenphone")
    public CommonResult tokenPhone()throws Exception{

        return businessService.tokenphone();
    }

}
